# NOT RUN {
# Save code in a file "demo.r" and run in 4 processors by
# > mpiexec -np 4 Rscript demo.r
### Setup environment.
library(pmclust, quiet = TRUE)
comm.set.seed(123)
### Generate an example data.
N.allspmds <- rep(5000, comm.size())
N.spmd <- 5000
N.K.spmd <- c(2000, 3000)
N <- 5000 * comm.size()
p <- 2
K <- 2
data.spmd <- generate.basic(N.allspmds, N.spmd, N.K.spmd, N, p, K)
X.spmd <- data.spmd$X.spmd
### Run clustering.
PARAM.org <- set.global(K = K) # Set global storages.
# PARAM.org <- initial.em(PARAM.org) # One initial.
PARAM.org <- initial.RndEM(PARAM.org) # Ten initials by default.
PARAM.new <- apecma.step(PARAM.org) # Run APECMa.
em.update.class() # Get classification.
### Get results.
N.CLASS <- get.N.CLASS(K)
comm.cat("# of class:", N.CLASS, "\n")
### Quit.
finalize()
# }
Run the code above in your browser using DataLab